package cn.glinks.liuhe.utils;

import android.os.CountDownTimer;

/**
 * Des:CountDownTimerUtils
 * 用于实现倒计时功能(不带暂停功能)
 *
 * @author MarsBlade of Cyh
 * @created 2017-03-22 9:42
 */
public class CountDownTimerUtils extends CountDownTimer {
    private CountDownTimerListener listener = null;

    /**
     * @param millisInFuture    The number of millis in the future from the call to
     *                          {@link #start()} until the countdown is done and
     *                          {@link #onFinish()} is called.
     * @param countDownInterval The interval along the way to receiver {@link #onTick(long)}
     *                          callbacks.
     */
    public CountDownTimerUtils(long millisInFuture, long countDownInterval,
                               CountDownTimerListener listener) {
        super(millisInFuture, countDownInterval);
        this.listener = listener;
    }

    @Override
    public void onTick(long millisUntilFinished) {
        if (listener != null) {
            listener.onTick(millisUntilFinished);
        }
    }

    @Override
    public void onFinish() {
        if (listener != null) {
            listener.onFinish();
        }
    }

    public interface CountDownTimerListener{
        public abstract void onTick(long millisUntilFinished);
        public abstract void onFinish();
    }
}